//
//  HLOtherRemindContentView.m
//  YueYue
//
//  Created by hulu001 on 2023/6/13.
//

#import "HLOtherRemindContentView.h"
#import "HLOtherRemidAttach.h"
#import "HLIMKitMessageModel.h"

@implementation HLOtherRemindContentView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.bubbleImageView.hidden = YES;
    
    self.backgroundColor = UIColorWhite;
    self.layer.cornerRadius = 8;
    self.layer.masksToBounds = YES;
    
    YYLabel *msgLabel = [YYLabel.alloc init];
    msgLabel.textAlignment = NSTextAlignmentCenter;
    msgLabel.textColor = UIColor.whiteColor;
    msgLabel.font = [UIFont systemFontOfSize:12];
    msgLabel.numberOfLines = 2;
    msgLabel.userInteractionEnabled = NO;
    [self addSubview:msgLabel];
    self.contentLabel = msgLabel;
    [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(26);
        make.right.mas_equalTo(-26);
        make.top.bottom.mas_equalTo(0);
    }];
}

- (void)refreshData:(HLIMKitMessageModel *)messageModel
{
    [super refreshData:messageModel];
    
    NIMCustomObject *object = (NIMCustomObject *)messageModel.message.messageObject;
    HLOtherRemidAttach *attachment = (HLOtherRemidAttach *)object.attachment;
    
    
    self.contentLabel.textColor = UIColorWhite;
    if (attachment.msgType == 19) {
        self.contentLabel.text = attachment.content;
        self.contentLabel.textColor = UIColorRed;
    } else if (attachment.msgType == 20) {
        self.contentLabel.text = attachment.messageContent;
        self.contentLabel.textColor = UIColorWhite;
    } else if (attachment.msgType == 21) {
        self.contentLabel.text = attachment.messageContent;
        self.contentLabel.textColor = UIColorWhite;
    } else {
        NSString *text = [NSString stringWithFormat:@"%@ %@", attachment.tittle,attachment.content];
        NSMutableAttributedString *attString = [NSMutableAttributedString.alloc initWithString:text];
        [attString yy_setColor:HLTextColor1 range:NSMakeRange(0, attString.length)];
        [attString yy_setAlignment:NSTextAlignmentCenter range:NSMakeRange(0, attString.length)];
        [attString yy_setTextHighlightRange:[text rangeOfString:attachment.content] color:HLMainColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            
        }];
        self.contentLabel.attributedText = attString;
    }
    

    
}

@end
